﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace jnxcLogin
{
    /// <summary>
    /// CheckUser 的摘要说明
    /// </summary>
    public class CheckUser : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
                       
            QueryLevel(context);

        }        
        public void QueryLevel(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("Access-Control-Allow-Origin", "*"); 
            string ac = "",uid="";
            if (null != context.Request.QueryString["type"])
            {//获取前台传来的值  
                ac = context.Request.QueryString["type"].ToString().Trim();
            }
            if (null != context.Request.QueryString["uid"])
            {//获取前台传来的值  
                uid = context.Request.QueryString["uid"].ToString().Trim();
            }
            //if (null != context.Request.QueryString["uname"])
            //{//获取前台传来的值  
            //    uname = context.Request.QueryString["uname"].ToString().Trim();
            //}
            Maticsoft.BLL.UserInfo um = new Maticsoft.BLL.UserInfo();
            string sql = "";
            string json = "";
            if(ac=="fz")
            {
                sql = "sys_FZ_uid=";
            }
            else if (ac == "cb")
            {
                sql = "sys_CB_uid=";
            }
            else if (ac == "jy")
            {
                sql = "sys_JY_uid=";
            }
            else if (ac == "px")
            {
                sql = "sys_PX_uid=";
            }
            else if (ac == "sb")
            {
                sql = "sys_SB_uid=";
            }
            if (sql != "")
            {
                sql += uid;
            }
            DataSet ds=um.GetList(sql);
            if (ds.Tables[0].Rows.Count != 0)
            {
                json = "[{\"fz\":\"" + ds.Tables[0].Rows[0]["sys_FZ_uid"].ToString() + "\",\"cb\":\"" + ds.Tables[0].Rows[0]["sys_CB_uid"].ToString() + "\",\"sb\":\"" + ds.Tables[0].Rows[0]["sys_SB_uid"].ToString() + "\",\"jy\":\"" + ds.Tables[0].Rows[0]["sys_JY_uid"].ToString() + "\"}]";
            }
            else
            {
                json = "[{\"fz\":\"\",\"cb\":\"\",\"sb\":\"\",\"jy\":\"\"}]";
            }
            context.Response.Write(json);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}